package com.whut.coc.infrastructure.persistence.jpa.impl;

import com.whut.coc.domain.model.coc.valueobject.UserTag;
import com.whut.coc.domain.repository.UserTagRepository;
import com.whut.coc.infrastructure.persistence.jpa.convert.COCConverter;
import com.whut.coc.infrastructure.persistence.jpa.entity.UserTagPO;
import com.whut.coc.infrastructure.persistence.jpa.service.IUserTagService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: Zonghe Wang
 * @Date: 2025/6/22 16:12
 */
@Repository
@RequiredArgsConstructor
public class UserTagRepositoryImpl implements UserTagRepository {

    private final IUserTagService userTagService;

    @Override
    public Boolean save(UserTag userTag) {

        UserTagPO po = COCConverter.toPO(userTag);

        return userTagService.save(po);
    }

    @Override
    public List<String> queryByUid(Long uid) {

        return userTagService.lambdaQuery()
                .eq(UserTagPO::getUid, uid)
                .list().stream()
                .filter(Objects::nonNull)
                .map(UserTagPO::getTag)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}
